<?php
require_once (dirname(__FILE__)."/../config/config.php");
?>
<?php 
	if($_REQUEST['method']=='addOrder'){
	$confirm=$_REQUEST['confirm'];
	if(strstr($confirm,"\\")==true){
		$confirmstr=str_replace("\\","",$confirm);
	}else{
		$confirmstr=$confirm;
	}
	$confirmArr=unserialize($confirmstr);
	
	$finalise=$_REQUEST['finalise'];
	if(strstr($finalise,"\\")==true){
		$finalisestr=str_replace("\\","",$finalise);
	}else{
		$finalisestr=$finalise;
	}
	$finaliseArr=unserialize($finalisestr);
	
	$addon=$_REQUEST['addon'];
	if(strstr($addon,"\\")==true){
		$addonstr=str_replace("\\","",$addon);
	}else{
		$addonstr=$addon;
	}
	$addonArr=unserialize($addonstr);
	
	$persondetail=$_REQUEST['persondetail'];
	if(strstr($persondetail,"\\")==true){
		$persondetailstr=str_replace("\\","",$persondetail);
	}else{
		$persondetailstr=$persondetail;
	}
	$persondetailArr=unserialize($persondetailstr);

	array_pop($confirmArr);
	array_pop($finaliseArr);
	array_pop($addonArr);
	array_pop($persondetailArr); 
	foreach ( $confirmArr as $cKey => $cValue ) {
		$confirmKey.=$cKey.",";
		$confirmValue.="'$cValue'".",";
	}
	
	foreach ( $finaliseArr as $fKey => $fValue ) {
		$finaliseKey.=$fKey.",";
		$finaliseValue.="'$fValue'".",";
	}
	
	foreach ( $addonArr as $aKey => $aValue ) {
		$addonKey.=$aKey.",";
		$addonValue.="'$aValue'".",";
	}
	
	foreach ( $persondetailArr as $pKey => $pValue ) {
		$persondetailKey.=$pKey.",";
		$persondetailValue.="'$pValue'".",";
	}
	
	$totalKey=$confirmKey.$finaliseKey.$addonKey.$persondetailKey;
	$totalValue=$confirmValue.$finaliseValue.$addonValue.$persondetailValue;
	$newtotalKey=substr($totalKey,0,strlen($totalKey)-1);
	$newtotalValue=substr($totalValue,0,strlen($totalValue)-1);
	$randomNumber=rand(1000,10000);
	$oderNo=date("Y-m-d H:i:s").$randomNumber;
	$sqlorderinsert="insert into zy_order(orderNo,$newtotalKey) value ('$oderNo',$newtotalValue)";
	mysql_query($sqlorderinsert);
	echo 'success';
	}
	
	//生成4位随机数
//	function getRandomNumber()
//	{
//		$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
//		for($i = 0; $i <3; $i++) {
//			$randomNumber .= $pattern{rand(0, 61)};
//		}
//		return $randomNumber;
//	}
?>